/**
 * Created by yangfan on 2016/10/18.
 */
define(['config/appregister',"i18n","business/personMine/services/httpServices","business/services/components"],function(app,i18n,personHttpService){
    app.controller('myVediosCtrl', function($scope,$state) {
        //初始值
        $scope.myType='myOrders';
        $scope.cancleFlag=false;
        $scope.delFlag=false;
        //我的学习和我的订单切换
        $scope.changeTabs=function(str){
            $scope.myType=str;
        };
        //关闭弹层
        $scope.closeConfirm=function(str){
            if(str=='cancle'){
                $scope.cancleFlag=false;
                return;
            }
            if(str=='del'){
                $scope.delFlag=false;
                return;
            }
        };

        /*我的学习相关js开始*/
        $scope.i18n = i18n;
        $scope.everPageShow = [30,50,100];

        $scope.tableTitle = ["课程信息","培训机构","最后学习时间","操作"];
        $scope.titleNavation = [
            {title:"我评论的",type:"myComment"},
            {title:"评论我的",type:"commented"},
        ];
        $scope.isShowCurrent = [];
        $scope.isShowCurrent[0] = true;
        $scope.isMyComment = true;
        $scope.byComment = false;
        $scope.noContent = "您暂时没有学习的课程";
        //待切换加载数据
        $scope.checkTitle = function(type,index){
            $scope.isShowCurrent = [];
            $scope.isShowCurrent[index] = true;
            if(index == 0){
                $scope.isMyComment = true;
                $scope.byComment = false;
                init();
            }else if(index ==1){
                $scope.isMyComment = false;
                $scope.byComment = true;
                getCommentForMe()
            }
        };


        $scope.isCurrent = [];
        $scope.isCurrent[0] = "bold";
        $scope.listParams = {
            pageNo:1,
            pageSize:10
        };
        function getPgination(){
            $scope.paginationConf = {
                currentPage: $scope.listParams.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage: $scope.listParams.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItem/$scope.listParams.pageSize),
                // 实际分页长度
                pagesLength: 5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function () {
                    $scope.list = [];
                    $scope.listParams.pageNo = $scope.paginationConf.currentPage;
                    getMyCourse();
                }

            };
            $scope.everPageShow = $scope.paginationConf.perPageOptions;
        }

        function getMyCourse(){
            var req = {
                type:"GET",
                uri:"getMyCourse",
                data:{
                    pageNo:$scope.listParams.pageNo,
                    pageSize:$scope.listParams.pageSize
                }
            };
            personHttpService.getMyCourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.videos = response.data.list;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    getPgination();
                });
            }).error(function(){})

        }
        getMyCourse();

        function cancelCourseEnroll(){
            var req = {
                type:"GET",
                uri:"cancelCourseEnroll",
                data:{
                    //删不准
                    courseId :$scope.curCourseId,
                }
            };
            personHttpService.cancelCourseEnroll(req).success(function(response){
                $scope.$apply(function(){
                    $scope.dialogModel.isShow =false;
                    getMyCourse();
                });

            }).error(function(){
                $scope.$apply(function(){
                    $scope.dialogModel.isShow =false;
                });
            })

        }

        //点击退出
        $scope.back = function(item){
            $scope.curCourseId = item.courseId;
            $scope.dialogModel.title = item.title ;
            $scope.dialogModel.isShow =true;
        };
        //改变每页预览条数
        $scope.changeItemsPerPage = function(item ,index){
            $scope.isCurrent = [];
            $scope.isCurrent[index] = "bold";

            $scope.listParams.pageNo = 1;
            $scope.listParams.pageSize = item;
            $scope.paginationConf.itemsPerPage = item;
            $scope.paginationConf.numberOfPages = parseInt($scope.totalItem/$scope.listParams.pageSize);
            //  $scope.$broadcast("numberOfPagesChange",{});
            init();
        };

        //跳转视频页
        $scope.goVedio = function(item){
            $state.go('eng.vedioDetails',{courseId:item.courseId})
        }
        /*我的学习相关js结束*/
    })
});